package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;


@Data
@Slf4j
@Component//<bean id="" class="" init-method="" destroy-method="">  @PostConstruct @PreDestroy
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {

    private String pubKeyPath;
    private String priKeyPath;

    private LoadUserInfo user = new LoadUserInfo();

    //在当前对象创建完成并且私有属性被DI赋值后创建出两个key。
    private PrivateKey privateKey;
    private PublicKey publicKey;

    @Data
    public class LoadUserInfo{
        private int expire;
        private String cookieName;
        private String cookieDomain;
    }

    @PostConstruct
    public void createKey() throws Exception {
        privateKey = RsaUtils.getPrivateKey(priKeyPath);
        publicKey = RsaUtils.getPublicKey(pubKeyPath);
    }





}